Repository navigation
fix(cli): resolve tsconfig aliases in database seeds - #873
karthickeyan-dev wants to merge 12 commits into
Conversation
cpojer
left a comment
There was a problem hiding this comment.
The TypeScript case looks good now and routeUrl() still works. The JavaScript behavior worries me though. Can we make .mjs and ESM .js use the same alias resolution as .ts, including for await import()?
Right now, with the same import and tsconfig, seed.ts seeds from the local fixture, but seed.mjs seeds from node_modules if there’s a package with the same name. Changing the file extension shouldn’t change what data ends up in the database.
One smaller thing: a seed that doesn’t use aliases used to work before void prepare. Now it fails if .void/tsconfig.json is missing. Can we update it so the error tells people to run void prepare?
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
# Conflicts: # packages/void/src/cli/db.ts
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f46892910a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Fall back to jiti when node:module has no registerHooks (Bun), resolve extensionless subpaths into packages without exports, load .tsx helpers, and skip .json files for path targets as TypeScript does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Merged
Known limits I left as they are:
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a33334700c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
App modules get named exports from JSON files and CommonJS modules, ESM-syntax JavaScript in a CommonJS app keeps require and __dirname, and extensionless absolute paths resolve as relative ones do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Running a CommonJS module inside the load hook changed evaluation order, could hit Node's require(esm) race guard, and changed what packages in node_modules received. CommonJS imports keep Node's export detection. JSON named exports now skip a byte order mark, __proto__, and malformed keys, and Windows drive paths get the extension fallback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9b7b35b8e6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
|
This PR was closed and its branch deleted before my last push, so |
`void db seed` now resolves the path aliases in the app's `tsconfig.json` (such as `@schema` and `@auth-schema`) in seed files and schema modules, including dynamic `import()`. Closes #872. This continues #873 by @karthickeyan-dev, which was closed with its branch deleted. Their commits are kept as they were. ## How it works ``` seed / schema import ├─ Node with tsconfig paths or baseUrl │ └─ node:module registerHooks │ ├─ aliases: app modules only (not node_modules or other packages) │ ├─ .d.ts targets skipped, so `void/routes` keeps its runtime code │ ├─ .ts/.tsx/.mts/.cts compiled with esbuild │ └─ keeps jiti's leniency: extensionless paths, `lodash/range`, │ named JSON imports, require/__dirname in promoted .js └─ no paths, or Bun (no registerHooks) → jiti, as before ``` A missing `.void/tsconfig.json` stops the seed before the reset and says to run `void prepare`. ## Known limits - CommonJS named imports use Node's export detection. A package whose names Node cannot see needs a default import. - `export { SomeType } from './types'` without `type` fails to link. TypeScript's `isolatedModules` reports the same thing. ## Verification - `packages/void/test/unit/db-seed.test.ts`: 36 tests. Each case added after #873's last commit failed before its fix. - `vp check`, `vp run test` (178/178 tasks). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: karthic <jkarthickeyan24@gmail.com> Co-authored-by: Christoph Nakazawa <cnakazawa@cloudflare.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fa6ea31ff6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return { format: 'commonjs', source: code, shortCircuit: true }; | ||
| } | ||
| const loader = sourcefile.endsWith('.tsx') ? 'tsx' : 'ts'; | ||
| return { format: 'module', source: compileToEsm(sourcefile, loader), shortCircuit: true }; |
There was a problem hiding this comment.
Preserve CommonJS exports in TypeScript seed modules
On Node, when runtime paths or baseUrl enables this loader, a CommonJS-style .ts seed such as exports.seed = async () => {} is compiled to ESM. Esbuild exposes its CommonJS exports object as a single default export, but importModule only unwraps Node's module.exports marker. Consequently, loadSeedFunction finds neither mod.seed nor a function-valued mod.default and rejects a named seed that Jiti previously loaded. The same conversion makes loadSeedSchema discard CommonJS schema exports when it filters out default. Preserve CommonJS output or normalize its generated wrapper instead of unconditionally promoting these TypeScript modules to ESM.
Useful? React with 👍 / 👎.
void db seednow resolves seed and schema imports using the application's tsconfig paths, including@auth-schemareferences used by foreign keys.Build a runtime path map with
get-tsconfig, excluding.d.ts,.d.mts, and.d.ctstargets while preserving inheritance, base URLs, wildcards, and fallback targets. This prevents generated aliases such asvoid/routesfrom replacing runtime helpers with declarations. Jiti receives a temporary config that remains available through seed execution and is removed afterwards.Regression coverage exercises auth foreign keys, schema files and directories, generated declaration aliases with
routeUrl(), mixed declaration/runtime targets, dynamic imports, and CommonJS JavaScript seeds. The seeding guide documents alias support.Closes #872.
Validation:
vp run build:all,vp check,vp run check:types, and build-artifact checksvp run test --listandvp run testvp test run: 827 files and 17,827 tests passed; 1 file and 39 tests skippedvoid preparefollowed by a SQLite seed using generated aliases,routeUrl(), and a dynamic@schemaimport